import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 全局储存用户的菜单
    menuList: [],
    actionList: {},
    // 储存客户可以访问的routers
    routers: []
  },
  mutations: {
    changeMenuList: function (state, list) {
      //初始化
      state.routers = []
      state.menuList = list
      list.forEach(menu => {
        //console.log(menu)
        menu.children.forEach(action => {
          var actionList = []
          action.children.forEach(v => {
            let b = (v.id).toString()
            let actionId = b.slice(-1)
            actionList.push(actionId)
          })
          Vue.set(state.actionList,action.menuUrl,actionList)
          state.routers.push(action.menuUrl)
        })
      })
    }
  },
  // actions: {
  //   changeMenuList: function (method, list) {
  //     method.commit('changeMenuList', list)
  //   }
  // },
  getters: {
    menuList: function (state) {
      return state.menuList
    },
    actions: function (state) {
      return state.actionList
    },
    routers: function (state) {
      return state.routers
    }
  }
})
